/*
 * Filename: g:\espidf_workspace\idf_S3_T-Watch\main\devices\sensor_bus.cc
 * Path: g:\espidf_workspace\idf_S3_T-Watch\main\devices
 * Created Date: Friday, June 20th 2025, 3:35:00 pm
 * Author: sss
 *
 * Copyright (c) 2025 Your Company
 */
#include "sensor_bus.h"
#include "driver/i2c_master.h"

static const char *TAG = "SENSOR_BUS";

static i2c_master_bus_handle_t i2c_bus_handle;
static bool i2c_bus_handle_inited = false;
i2c_master_bus_handle_t get_i2c_bus_handle()
{
    if (!i2c_bus_handle_inited)
    {
        i2c_master_bus_config_t i2c_bus_config = {
            .i2c_port = SENSOR_I2C_BUS,
            .sda_io_num = SENSOR_I2C_GPIO_SDA,
            .scl_io_num = SENSOR_I2C_GPIO_SCL,
            .clk_source = I2C_CLK_SRC_DEFAULT,
            .glitch_ignore_cnt = 7,
            .intr_priority = 0,
            .flags = {
                .enable_internal_pullup = true,
            }
        };

        ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_config, &i2c_bus_handle));
        i2c_bus_handle_inited = true;
    }

    return i2c_bus_handle;
}
